import axios from "@/axios"

export function getArticleDetail(articleId) {
    return axios.post("/user/article/detail", {articleId})
}

export function publishArticle(data) {
    return axios.post("/user/article/publish", data)
}

export function getArticlePageList(data) {
    // 确保有正确的分页参数
    if (!data.current && data.pageNum) {
        data.current = data.pageNum;
    }
    if (!data.size && data.pageSize) {
        data.size = data.pageSize;
    }
    
    // 如果没有设置分页参数，设置默认值
    if (!data.current) {
        data.current = 1;
    }
    if (!data.size) {
        data.size = 10;
    }
    
    console.log('文章列表请求参数:', data);
    return axios.post("/user/article/list", data)
}

export function deleteArticle(articleId) {
    return axios.post("/user/article/delete", {articleId})
}

export function updateArticle(data) {
    return axios.post("/user/article/update", data)
}

export function getUserArticleCount() {
    return axios.post("/user/article/count");
}

export function getUserArticleCategoryDistribution() {
    // 尝试直接请求文章分类分布API
    return axios.post("/article/category/distribution");
}